package com.zhang.controller;


import com.github.pagehelper.PageInfo;
import com.zhang.domain.Department;
import com.zhang.domain.LoginInfo;
import com.zhang.domain.Manager;
import com.zhang.domain.Shop;
import com.zhang.query.EmployeeQuery;
import com.zhang.query.ShopQuery;
import com.zhang.service.IEmpService;
import com.zhang.service.IShopService;
import com.zhang.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zh
 * @create 2022-02-14 9:06
 */

@RestController
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private IShopService service;
    @PutMapping
    private AjaxResult addOrUpdate(@RequestBody Shop m){
        if(m.getId()!=null){
            try {
                service.update(m);
                return AjaxResult.me();
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.me(false,"修改失败");
            }
        }else {
            try {
                service.save(m);
                return AjaxResult.me();
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.me(false,"添加失败");
            }
        }
    }
    @DeleteMapping("/{id}")
    private AjaxResult delete(@PathVariable("id") Long id){
        try {
            service.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me(false,"删除失败");
        }
    }
    @PostMapping
    private AjaxResult getAllData(@RequestBody ShopQuery query){
        try {
            PageInfo<Shop> pageInfo = service.queryData(query);
            return AjaxResult.me(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me(false,"查询失败");
        }
    }
    @GetMapping("/selAllEmp")
    private AjaxResult selAllEmp(){
        try {
            List<Manager> strings = service.selAllEmp();
            return AjaxResult.me(strings);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me(false,"查询失败");
        }
    }
}
